<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2024/4/12
  Time: 9:06
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" import="java.time.* ,java.text.*,java.util.*" %>
<html>
<head>
    <title>实验二：显示日期时间</title>
</head>
<body>
<%
    LocalDate date = LocalDate.now();
    LocalTime time = LocalTime.now();
    out.print("用户在" + date.getYear() + "年" + date.getMonthValue() + "月" + date.getDayOfMonth()
            + "日" + time.getHour() + "时" + time.getMinute() + "分" + time.getSecond()
            + "秒访问了该网页<br>");
%>
<%
    out.print("用户在" + (new SimpleDateFormat("yyyy年M月d日 H时m分s秒").format(new Date())) + "访问了该网页<br>");
%>
<h3>北京时间：<span id="time"></span></h3>
<script>
    function getTime() {
        const now = new Date();
        const week = ["日", "一", "二", "三", "四", "五", "六"];
        document.getElementById("time").innerText = now.getFullYear() + "/" + (now.getMonth() + 1)
            + "/" + now.getDate() + " " + now.getHours() + ":" + now.getMinutes() + ":"
            + now.getSeconds() + " 周" + week[now.getDay()];
    }

    window.onload = function () {
        getTime();
        setInterval(getTime, 1000);
    }
</script>
</body>
</html>
